export default {
  data: () => ({
    drawerStatus: '',
    drawerVisible: false,
    editIndex: ''
  }),
  methods: {
    // 添加设备
    async rowHandle(status, rowInfo, index) {
      this.drawerStatus = status
      this.getTemp(status, rowInfo)
        .then((res) => {
          this.editIndex = index
          this.temp = res
          this.drawerVisible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].clearValidate()
          })
        })
        .catch()
    },
    // 添加设备提交
    rowSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          var requestHandle =
            this.drawerStatus === 'edit' ? this.editRequest : this.addRequest
          if (typeof requestHandle === 'function') {
            requestHandle().then((ret) => {
              if (ret.success) {
                this.drawerVisible = false
                if (this.$refs.table) {
                  this.$refs.table.getData(ret)
                } else {
                  this.getData(ret)
                }
              }
            })
          }
          // this.$message({
          //   type: 'success',
          //   message: `${this.textMap[this.drawerStatus]}成功`
          // })
        }
      })
    },
    // 删除设备
    deleteRow(rowInfo, index) {
      this.$confirm(`确定要删除此条数据`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.deleteSubmit(index)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
